﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NabNetLib.Packet
{
    #region enums
    public enum AmbientServiceType
    {
        DisableService = 0,
        ServiceWeather = 1,
        ServiceStockMarket = 2,
        ServicePeriph = 3,
        MoveLeftEar = 4,
        MoveRightEar = 5,
        ServiceEMail = 6,
        ServiceAirQuality = 7,
        ServiceNose = 8,
        ServiceTaiChi = 0x0e
    };

    public enum WeatherValues
    {
        WeatherSun = 0,
        WeatherCloudy = 1,
        WeatherSmog = 2,
        WeatherRain = 3,
        WeatherSnow = 4,
        WeatherStorm = 5
    };

    public enum StockMarketValues
    {
        StockMarketHighDown = 0,
        StockMarketMediumDown = 1,
        StockMarketLittleDown = 2,
        StockMarketStable = 3,
        StockMarketLittleUp = 4,
        StockMarketMediumUp = 5,
        StockMarketHighUp = 6
    };

    public enum EMailValues
    {
        EMailNo = 0,
        EMail1 = 1,
        EMail2 = 2,
        EMail3AndMore = 3
    };

    public enum NoseValues
    {
        NoseNo = 0,
        NoseBlink = 1,
        NoseDoubleBlink = 2
    };

    #endregion

    public class AmbientPacket : Packet
    {
        private Dictionary<AmbientServiceType, byte> mServices = new Dictionary<AmbientServiceType, byte>();


        public AmbientPacket()
        {
        }

        public AmbientPacket(AmbientServiceType service, byte val)
        {
            SetServiceValue(service, val);
        }

        public void SetServiceValue(AmbientServiceType service, byte val)
        {
            mServices[service] = val;
        }

        public void SetEarsPosition(byte left, byte right)
        {
            mServices[AmbientServiceType.MoveLeftEar] = left;
            mServices[AmbientServiceType.MoveRightEar] = right;
        }

        public void DisableService(AmbientServiceType service)
        {
            if (mServices.ContainsKey(service))
            {
                mServices.Remove(service);
            }

            mServices[AmbientServiceType.DisableService] = (byte) service;
        }


        public override PacketType GetPacketType()
        {
            return PacketType.Ambient;
        }

        protected override byte[] GetInternalData()
        {
            List<byte> tmp = new List<byte>(new byte[]{0x7F,0xFF,0xFF,0xFE});
            foreach(AmbientServiceType service in mServices.Keys)
            {
                tmp.Add((byte)service);
                tmp.Add(mServices[service]);
            }
            return tmp.ToArray();
        }

    }
}
